package com.tth.learn.addproperties.java;

import org.junit.Test;

/**
 * 枚举类的使用
 * 方式一：jdk5.0之前，自定义枚举类
 * @Author tth
 * @Date 2022/12/8 10:24
 */
public class SeasonTest {

    @Test
    public void test1() {
        Season summer = Season.SUMMER;
        System.out.println(summer.toString());
    }
}

/**
 * 季节枚举类
 */
class Season {
    // 1.声明季节的属性
    private final Integer seasonCode;
    private final String seasonName;
    private final String seasonDesc;

    // 2.私有化构造器
    private Season(Integer seasonCode, String seasonName, String seasonDesc) {
        this.seasonCode = seasonCode;
        this.seasonName = seasonName;
        this.seasonDesc = seasonDesc;
    }

    // 3.提供当前枚举类的对象，修饰符为public static final
    public static final Season SPRING = new Season(1001, "春天", "春暖花开");
    public static final Season SUMMER = new Season(1002, "夏天", "烈日炎炎");
    public static final Season AUTUMN = new Season(1003, "秋天", "瓜果飘香");
    public static final Season WINTER = new Season(1004, "冬天", "白雪皑皑");

    // 4.其他诉求1：生成季节属性的getter，以获取Season对象实例的属性
    public Integer getSeasonCode() {
        return seasonCode;
    }

    public String getSeasonName() {
        return seasonName;
    }

    public String getSeasonDesc() {
        return seasonDesc;
    }

    // 4.其他诉求2：生成toString()方法
    @Override
    public String toString() {
        return "Season{" +
                "seasonCode=" + seasonCode +
                ", seasonName='" + seasonName + '\'' +
                ", seasonDesc='" + seasonDesc + '\'' +
                '}';
    }
}
